﻿using System;
using System.Web.UI.WebControls;
using Lswweb.Model;
using Lswweb.Domain;
using Lswweb.Controls;

namespace Lswweb.Controls
{
    public class UserRegister : SkinnedWebControl
    {
        #region 成员字段和构造方法

        private UserMembership userMembership;
        private UserProfile userProfile;
        private IButtonControl btnConfirm;

        #endregion

        #region 初始化控件

        protected override void InitializeSkin(System.Web.UI.Control skin)
        {
            userMembership = (UserMembership)skin.FindControl("userMembership");
            userProfile = (UserProfile)skin.FindControl("userProfile");
            btnConfirm = (IButtonControl)skin.FindControl("btnConfirm");

            btnConfirm.Click += new EventHandler(btnConfirm_Click);
        }

        void btnConfirm_Click(object sender, EventArgs e)
        {
            UserInfo userInfo = userMembership.MembershipInfo;
            if (this.userProfile != null)
                userInfo.Profile = this.userProfile.ProfileInfo;

            Users.AddUser(userInfo);
        }

        #endregion

        #region 属性

        private int UserId
        {
            get { return SiteContext.Current.Id; }
        }

        #endregion

        protected override string DefaultSkinFilename
        {
            get { return "User/UserRegister.ascx"; }
        }
    }
}
